Reading in MappingMuseumData:
museum_df <- read_csv("MappingMuseumsData2021_09_30.csv")
Rows: 4191 Columns: 35── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (24): museum_id, Name_of_museum, Address_line_1, Address_line_2, Village,_Town_or_City, Postcode, Admin_area, Accreditation, Governa...
dbl (11): Latitude, Longitude, DOMUS_identifier, Area_Deprivation_index, Area_Deprivation_index_crime, Area_Deprivation_index_education,...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
tidy_museum_df <- museum_df %>%
pivot_longer(cols = c(starts_with("Area_Deprivation_Index")), names_to = "Area_Deprivation_Type", values_to = "Area_Deprivation_Score") %>%
select(-ends_with("_provenance"),-starts_with("DOMUS"),-ends_with("_code")) %>%
mutate(status = "open") %>%
mutate(status = ifelse(Year_closed != "9999:9999","closed",status))
tidy_museum_sum <- tidy_museum_df %>%
filter(Area_Deprivation_Type != "Area_Deprivation_index") %>%
separate(col = "Area_Deprivation_Type", into = c(NA,NA,NA,"Area_Deprivation_Type"),sep = "_") %>%
group_by(Area_Deprivation_Type,Area_Deprivation_Score,status) %>%
summarize(n = n())
`summarise()` has grouped output by 'Area_Deprivation_Type', 'Area_Deprivation_Score'. You can override using the `.groups` argument.
ggp <- ggplot(tidy_museum_sum,aes(x = Area_Deprivation_Score,y = n, fill = status)) +
geom_col(position = "dodge") +
facet_wrap("Area_Deprivation_Type",) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 10)) +
theme_classic()
ggplotly(ggp,tooltip = c("x","y","status"))